

using System;
using System.Collections.Generic;
using System.Text;

using JTC.MiniCommerce.Core.Configuration;
using System.Globalization;
using System.Xml.Serialization;

namespace JTC.MiniCommerce.Store {
  [Serializable()]
  public class SiteSettings {

    #region Constants

    public const string SECTION_NAME = "siteSettings";

    #endregion

    #region Member Variables

    private string _language;
    private string _currency;
    private string _theme;
    private string _analytics;
    private string _siteName;
    private bool _displayRetailPrice;
    private bool _displayNarrowByManufacturer;
    private bool _displayNarrowByPrice;
    private bool _requireSsl = true;
    private string _tagLine;
    CultureInfo _cultureInfo;
    private bool _collectBrowsingCategory;
    private bool _collectBrowsingProduct;
    private int _catalogItems = 6;
    private string _siteLogo;
    private LoginRequirement _loginRequirement;
    private bool _collectSearchTerms = true;
    private string _newsFeedUrl;
   

    #endregion

    #region Methods

    #region Public

    /// <summary>
    /// Loads this instance.
    /// </summary>
    /// <returns></returns>
    public static SiteSettings Load() {
      DatabaseConfigurationProvider databaseConfigurationProvider = new DatabaseConfigurationProvider();
      SiteSettings siteSettings = databaseConfigurationProvider.FetchConfigurationByName(SiteSettings.SECTION_NAME) as SiteSettings;
      return siteSettings;
    }

    #endregion

    #endregion

    #region Properties

    /// <summary>
    /// Gets or sets the site logo.
    /// </summary>
    /// <value>The site logo.</value>
    public string SiteLogo {
      get {
        return _siteLogo;
      }
      set {
        _siteLogo = value;
      }
    }

    /// <summary>
    /// Gets or sets the name of the site.
    /// </summary>
    /// <value>The name of the site.</value>
    public string SiteName {
      get {
        return _siteName;
      }
      set {
        _siteName = value;
      }
    }

    /// <summary>
    /// Gets or sets the tag line.
    /// </summary>
    /// <value>The tag line.</value>
    public string TagLine {
      get {
        return _tagLine;
      }
      set {
        _tagLine = value;
      }
    }

    /// <summary>
    /// Gets or sets the login requirement.
    /// </summary>
    /// <value>The login requirement.</value>
    public LoginRequirement LoginRequirement {
      get {
        return _loginRequirement;
      }
      set {
        _loginRequirement = value;
      }
    }

    /// <summary>
    /// Gets or sets the news feed URL.
    /// </summary>
    /// <value>The news feed URL.</value>
    public string NewsFeedUrl {
      get {
        return _newsFeedUrl;
      }
      set {
        _newsFeedUrl = value;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether [require SSL].
    /// </summary>
    /// <value><c>true</c> if [require SSL]; otherwise, <c>false</c>.</value>
    public bool RequireSsl {
      get {
        return _requireSsl;
      }
      set {
        _requireSsl = value;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether [collect browsing category].
    /// </summary>
    /// <value>
    /// 	<c>true</c> if [collect browsing category]; otherwise, <c>false</c>.
    /// </value>
    public bool CollectBrowsingCategory {
      get {
        return _collectBrowsingCategory;
      }
      set {
        _collectBrowsingCategory = value;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether [collect browsing product].
    /// </summary>
    /// <value>
    /// 	<c>true</c> if [collect browsing product]; otherwise, <c>false</c>.
    /// </value>
    public bool CollectBrowsingProduct {
      get {
        return _collectBrowsingProduct;
      }
      set {
        _collectBrowsingProduct = value;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether [collect search terms].
    /// </summary>
    /// <value><c>true</c> if [collect search terms]; otherwise, <c>false</c>.</value>
    public bool CollectSearchTerms {
      get {
        return _collectSearchTerms;
      }
      set {
        _collectSearchTerms = value;
      }
    }

    /// <summary>
    /// Gets or sets the catalog items.
    /// </summary>
    /// <value>The catalog items.</value>
    public int CatalogItems {
      get {
        return _catalogItems;
      }
      set {
        _catalogItems = value;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether [display retail price].
    /// </summary>
    /// <value><c>true</c> if [display retail price]; otherwise, <c>false</c>.</value>
    public bool DisplayRetailPrice {
      get {
        return _displayRetailPrice;
      }
      set {
        _displayRetailPrice = value;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether [display narrow by manufacturer].
    /// </summary>
    /// <value>
    /// 	<c>true</c> if [display narrow by manufacturer]; otherwise, <c>false</c>.
    /// </value>
    public bool DisplayNarrowByManufacturer {
      get {
        return _displayNarrowByManufacturer;
      }
      set {
        _displayNarrowByManufacturer = value;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether [display narrow by price].
    /// </summary>
    /// <value>
    /// 	<c>true</c> if [display narrow by price]; otherwise, <c>false</c>.
    /// </value>
    public bool DisplayNarrowByPrice {
      get {
        return _displayNarrowByPrice;
      }
      set {
        _displayNarrowByPrice = value;
      }
    }

    /// <summary>
    /// Gets or sets the language.
    /// </summary>
    /// <value>The language.</value>
    public string Language {
      get {
        return _language;
      }
      set {
        _language = value;
      }
    }

    /// <summary>
    /// Gets or sets the currency code.
    /// </summary>
    /// <value>The currency code.</value>
    public string CurrencyCode {
      get {
        return _currency;
      }
      set {
        _currency = value;
      }
    }

    /// <summary>
    /// Gets or sets the theme.
    /// </summary>
    /// <value>The theme.</value>
    public string Theme {
      get {
        return _theme;
      }
      set {
        _theme = value;
      }
    }

    /// <summary>
    /// Gets or sets the analytics.
    /// </summary>
    /// <value>The analytics.</value>
    public string Analytics {
      get {
        return _analytics;
      }
      set {
        _analytics = value;
      }
    }

    /// <summary>
    /// Gets the currency symbol.
    /// </summary>
    /// <value>The currency symbol.</value>
    [XmlIgnore]
    public string CurrencySymbol {
      get {
        if(_cultureInfo == null) {
          _cultureInfo = new CultureInfo(this.Language);
        }
        return _cultureInfo.NumberFormat.CurrencySymbol;
      }
    }

    /// <summary>
    /// Gets the currency decimals.
    /// </summary>
    /// <value>The currency decimals.</value>
    [XmlIgnore]
    public int CurrencyDecimals {
      get {
        if(_cultureInfo == null) {
          _cultureInfo = new CultureInfo(this.Language);
        }
        return _cultureInfo.NumberFormat.CurrencyDecimalDigits;
      }
    }

    #endregion
    
  }
}
